package ase.eleitweg.client.gui;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;

public class Info_gui extends Dialog {

	protected Object result;
	protected Shell shell;
	
	private String reason = "";

	/**
	 * Create the dialog
	 * @param parent
	 * @param style
	 */
	public Info_gui(Shell parent, int style, String reason) {
		super(parent, style);
		this.reason = reason;
	}

	/**
	 * Create the dialog
	 * @param parent
	 */
	public Info_gui(Shell parent) {
		this(parent, SWT.NONE, "other info");
	}

	/**
	 * Open the dialog
	 * @return the result
	 */
	public Object open() {
		createContents();
		shell.open();
		shell.layout();
		Display display = getParent().getDisplay();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		return result;
	}

	/**
	 * Create contents of the dialog
	 */
	protected void createContents() {
		shell = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
		shell.setLayout(new FormLayout());
		shell.setSize(300, 150);
		shell.setText("SWT Dialog");

		final Composite composite = new Composite(shell, SWT.NONE);
		composite.setLayout(new GridLayout());
		final FormData fd_composite = new FormData();
		fd_composite.top = new FormAttachment(0, 75);
		fd_composite.bottom = new FormAttachment(100, -10);
		fd_composite.right = new FormAttachment(100, -5);
		fd_composite.left = new FormAttachment(0, 5);
		composite.setLayoutData(fd_composite);

		final Button okButton = new Button(composite, SWT.NONE);
		final GridData gd_okButton = new GridData(SWT.CENTER, SWT.CENTER, true, true);
		gd_okButton.widthHint = 80;
		okButton.setLayoutData(gd_okButton);
		okButton.addMouseListener(new MouseAdapter() {
			public void mouseUp(final MouseEvent e) {
				shell.close();
			}
		});
		okButton.setText("OK");

		Composite composite_1;
		composite_1 = new Composite(shell, SWT.NONE);
		final GridLayout gridLayout = new GridLayout();
		gridLayout.numColumns = 3;
		composite_1.setLayout(gridLayout);
		final FormData fd_composite_1 = new FormData();
		fd_composite_1.top = new FormAttachment(0, 25);
		fd_composite_1.bottom = new FormAttachment(100, -60);
		fd_composite_1.right = new FormAttachment(100, -5);
		fd_composite_1.left = new FormAttachment(0, 5);
		composite_1.setLayoutData(fd_composite_1);

		final Label label = new Label(composite_1, SWT.NONE);
		final GridData gd_label = new GridData(SWT.RIGHT, SWT.CENTER, false, false);
		gd_label.widthHint = 43;
		label.setLayoutData(gd_label);
		label.setImage(new Image( Display.getCurrent(), "icons/32/messagebox_warning.png"));

		final Label infoLable = new Label(composite_1, SWT.NONE);
		infoLable.setAlignment(SWT.CENTER);
		infoLable.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, true));
		infoLable.setText("Info:");

		final Label xLabel = new Label(composite_1, SWT.NONE);
		xLabel.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, true, true));
		xLabel.setText(reason);
		//
	}
	public static void main(String[] args) {
		try {
			Info_gui window = new Info_gui(new Shell(), 0, "");
			window.open();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
